package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.serve.domain.Floor;
import com.zzyl.serve.vo.FloorVo;
import com.zzyl.serve.vo.TreeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 楼层Mapper接口
 *
 * @author liuyp
 * @date 2025-07-30
 */
@Mapper
public interface FloorMapper extends BaseMapper<Floor> {
    /**
     * 查询楼层
     *
     * @param id 楼层主键
     * @return 楼层
     */
    public Floor selectFloorById(Long id);

    /**
     * 查询楼层列表
     *
     * @param floor 楼层
     * @return 楼层集合
     */
    public List<Floor> selectFloorList(Floor floor);

    /**
     * 新增楼层
     *
     * @param floor 楼层
     * @return 结果
     */
    public int insertFloor(Floor floor);

    /**
     * 修改楼层
     *
     * @param floor 楼层
     * @return 结果
     */
    public int updateFloor(Floor floor);

    /**
     * 删除楼层
     *
     * @param id 楼层主键
     * @return 结果
     */
    public int deleteFloorById(Long id);

    /**
     * 批量删除楼层
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFloorByIds(Long[] ids);

    /**
     * 查询所有楼层（负责老人）
     *
     * @return 结果
     */
    List<Floor> selectAllByNur();

    /**
     * 根据状态获取房间和床位信息
     *
     * @param status
     * @return
     */
    List<TreeVo> getRoomAndBedByBedStatus(Integer status);


    /**
     * @return
     */
    @Select("select distinct f.id,f.name,f.code from floor f " +
            "left join room r on f.id = r.floor_id " +
            "left join device d on d.binding_location = r.id and d.location_type = 1 and d.physical_location_type = 1 " +
            "left join bed b on r.id = b.room_id " +
            "left join device dd on dd.binding_location = b.id and dd.location_type = 1 and dd.physical_location_type = 2 " +
            "where d.id is not null or dd.id is not null")
    List<FloorVo> getAllFloorsWithDevice();
}
